{extend name='./content'}

{block name="content"}

<!-- 表单搜索 开始 -->
<nav class="ns-third-menu js-order-status-menu">
    <ul id="order_status_nav" data-menu-node="m-117-118">
        <li class="nav-item {if path('domain')==''}selected{/if}">
            <a data-title="正常" data-open='/admin/demand/domain' href="javascript:void(0)">正常域名</a>
        </li>
        <li class="nav-item {if path('domain')=='down'}selected{/if}">
            <a data-title="下架" data-open='/admin/demand/domain/down' href="javascript:void(0)">下架域名</a>
        </li>
        <li class="nav-item {if path('domain')=='audit'}selected{/if}">
            <a data-title="审核" data-open='/admin/demand/domain/audit' href="javascript:void(0)">审核域名</a>
        </li>
    </ul>
</nav>

<form class="layui-form  form-search" action="__SELF__" onsubmit="return false" method="get">
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">商户ID</label>
        <div class="layui-input-inline">
            <input name="user_id" value="{$Think.get.user_id|default=''}" placeholder="请输入商户ID" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">商户账号</label>
        <div class="layui-input-inline">
            <input name="username" value="{$Think.get.username|default=''}" placeholder="请输入商户账号" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">商品名</label>
        <div class="layui-input-inline">
            <input name="name" value="{$Think.get.name|default=''}" placeholder="请输入商品名" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
            <select name="status">
                <option value="">全部状态</option>
				<option value="0" {if $Think.get.zt === '0'}selected{/if}>待审核</option>
				<option value="1" {if $Think.get.zt === '1'}selected{/if}>已通过</option>
				<option value="2" {if $Think.get.zt === '2'}selected{/if}>未通过</option>				
                <option value="1" {if $Think.get.zt === '1'}selected{/if}>已上架</option>
                <option value="0" {if $Think.get.zt === '0'}selected{/if}>已下架</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">时间范围</label>
        <div class="layui-input-inline">
            <input name="date_range" id="date_range" value="{:urldecode($Think.get.date_range)}" placeholder="请选择时间范围" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-inline">
        <button type="submit" class="layui-btn layui-btn-primary layui-btn-small"><i class="layui-icon">&#xe615;</i> 搜 索</button>
    </div>

	<div class="layui-form-item layui-inline">
		<label class="layui-form-label">操作</label>
		<button id="go_down" type="button" class="layui-btn layui-btn-normal layui-btn-small">批量上下架</button>
	<button id="go_true" type="button" class="layui-btn layui-btn-normal layui-btn-small">批量通过</button>
	<button id="go_del" type="button" class="layui-btn layui-btn-normal layui-btn-small">批量删除</button>
	</div>	
</form>
<!-- 表单搜索 结束 -->
<form onsubmit="return false;" data-auto="" method="POST">
    <input type="hidden" value="resort" name="action"/>
    <table class="table table-hover">
        <thead>
        <tr>
            <th class='list-table-check-td'>
                <input data-none-auto="" data-check-target='.list-check-box' type='checkbox' />
            </th>
            <th>商品ID</th>		
            <th>商户名称</th>
            <th>商品名称</th>
            <th>商品价格</th>
            <th>审核状态</th>
            <th>添加时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $data as $v}
        <tr>
            <td class='list-table-check-td'>
                <input class="list-check-box" value='{$v.id}' type='checkbox' />
            </td>
            <td>{$v.id}</td>
			<td>{:uc_info($v.ubh,'buy','name')}</td>
            <td style="width: 30%;" ><a href="{:sysconf('site_domain')}/demand/{$v.id}.html" target="_blank">{:changdu($v.tit,28)}</a></td>
            <td>{$v.money}.00</td>			
			<td class='text-center'>
				<div class="layui-btn-group">
					<button type="button" class='layui-btn {if $v.zt==1}layui-btn-normal{else/}layui-btn-primary{/if} layui-btn-small btn-status-open' onclick="changeStatus({$v.bh},1)">通过</button>
					<button type="button" class='layui-btn {if $v.zt==0}layui-btn-normal{else/}layui-btn-primary{/if} layui-btn-small btn-status-close' onclick="changeStatus({$v.bh},0)">审核</button>
				</div>
			</td>						
            <td>{$v.sj}</td>  
            <td>
				<a href='{:url("admin/member/info")}?bh={$v.ubh}' class='layui-btn layui-btn-small' href="javascript:void(0)">商户</a>
				<button type="button" class='layui-btn layui-btn-small layui-btn-danger' onclick="del(this,'{$v.bh}','domain')">删除</button>
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
</form>
{$page}
<script>
    layui.use('form', function(){
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //日期范围
        laydate.render({
            elem: '#date_range',
            range: true
        });
    });

    function changeStatus(bh,status){
        $.ajax({
            url:'/admin/demand/status?action=status',
            type:'post',
            data:{bh:bh, status:status},
            success:function(res){
                if(res.code==1){
                    location.reload();
                }else{
                    alert(res.msg);
                }
            }
        });
    }


    function del(obj,bh,type) {
        layer.confirm('确定删除？删除后，商品将进入回收站！',function(val){
            if(val){
                $.post('/admin/demand/del',{
                    bh:bh,
					type:type
                },function(res){
                    if(res.code!=200){
                        layer.msg('删除失败');
                    }else{
                        layer.msg('删除成功！',function(){
                            location.reload();
                        });
                    }
                });
            }
        })
    }

    $('img').on('click', function () {
		layer.photos({
			photos: '.layui-table',
			shadeClose: false,
			closeBtn: 2,
			anim: 0
		});
	})
    // 批量上架
    $('#go_down').click(function () {
        var ids = '';
        $('.list-check-box').each(function () {
            var _this = $(this);
            if (_this.is(':checked')) {
                ids = ids + _this.val() + ',';
            }
        });
        layer.confirm('确定要批量上架吗', function (index) {
            if (ids == '') {
                layer.msg('请选择操作商品');
                return false;
            }
            $.ajax({
                url: "/admin/demand/go_down",
                type: 'post',
                data: {
                    'ids' : ids,
					'type': 'domain'
                },
                success: function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        });
                        $.form.reload();
                    } else {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        });
                    }
                }
            });
        });
    });
    // 批量通过
    $('#go_true').click(function () {
        var ids = '';
        $('.list-check-box').each(function () {
            var _this = $(this);
            if (_this.is(':checked')) {
                ids = ids + _this.val() + ',';
            }
        });
        layer.confirm('确定要批量通过吗', function (index) {
            if (ids == '') {
                layer.msg('请选择操作商品');
                return false;
            }
            $.ajax({
                url: "/admin/demand/go_true",
                type: 'post',
                data: {
                    'ids' : ids,
					'type': 'domain'
                },
                success: function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        });
                        $.form.reload();
                    } else {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        });
                    }
                }
            });
        });
    });

    // 批量删除
    $('#go_del').click(function () {
        var ids = '';
        $('.list-check-box').each(function () {
            var _this = $(this);
            if (_this.is(':checked')) {
                ids = ids + _this.val() + ',';
            }
        });
        layer.confirm('确定要批量删除吗', function (index) {
            if (ids == '') {
                layer.msg('请选择操作商品');
                return false;
            }
            $.ajax({
                url: "/admin/demand/go_del",
                type: 'post',
                data: {
                    'ids' : ids,
					'type': 'domain'
                },
                success: function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        });
                        $.form.reload();
                    } else {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        });
                    }
                }
            });
        });
    });
</script>
{/block}
